package com.joolun.web.controller.scrm;

import com.joolun.common.annotation.Log;
import com.joolun.common.core.controller.BaseController;
import com.joolun.common.core.domain.AjaxResult;
import com.joolun.common.core.page.TableDataInfo;
import com.joolun.common.enums.BusinessType;
import com.joolun.common.utils.poi.ExcelUtil;
import com.joolun.weixin.entity.ScrmChannelRecordLog;
import com.joolun.weixin.service.IScrmChannelRecordLogService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 渠道数据日志Controller
 * 
 * @author joolun
 * @date 2025-04-11
 */
@RestController
@RequestMapping("/system/log")
public class ScrmChannelRecordLogController extends BaseController
{
    @Autowired
    private IScrmChannelRecordLogService scrmChannelRecordLogService;

    /**
     * 查询渠道数据日志列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ScrmChannelRecordLog scrmChannelRecordLog)
    {
        startPage();
        List<ScrmChannelRecordLog> list = scrmChannelRecordLogService.selectScrmChannelRecordLogList(scrmChannelRecordLog);
        return getDataTable(list);
    }

    /**
     * 导出渠道数据日志列表
     */
    @PreAuthorize("@ss.hasPermi('system:log:export')")
    @Log(title = "渠道数据日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScrmChannelRecordLog scrmChannelRecordLog)
    {
        List<ScrmChannelRecordLog> list = scrmChannelRecordLogService.selectScrmChannelRecordLogList(scrmChannelRecordLog);
        ExcelUtil<ScrmChannelRecordLog> util = new ExcelUtil<ScrmChannelRecordLog>(ScrmChannelRecordLog.class);
        util.exportExcel(response, list, "渠道数据日志数据");
    }

    /**
     * 获取渠道数据日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:log:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(scrmChannelRecordLogService.selectScrmChannelRecordLogById(id));
    }

    /**
     * 新增渠道数据日志
     */
    @PreAuthorize("@ss.hasPermi('system:log:add')")
    @Log(title = "渠道数据日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScrmChannelRecordLog scrmChannelRecordLog)
    {
        scrmChannelRecordLog.setCreateBy(getUsername());
        return toAjax(scrmChannelRecordLogService.insertScrmChannelRecordLog(scrmChannelRecordLog));
    }

    /**
     * 修改渠道数据日志
     */
    @PreAuthorize("@ss.hasPermi('system:log:edit')")
    @Log(title = "渠道数据日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScrmChannelRecordLog scrmChannelRecordLog)
    {
        scrmChannelRecordLog.setCreateBy(getUsername());
        return toAjax(scrmChannelRecordLogService.updateScrmChannelRecordLog(scrmChannelRecordLog));
    }

    /**
     * 删除渠道数据日志
     */
    @PreAuthorize("@ss.hasPermi('system:log:remove')")
    @Log(title = "渠道数据日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(scrmChannelRecordLogService.deleteScrmChannelRecordLogByIds(ids));
    }
}
